<template>
	<view class="content">
		<view class="webview-content">
			<web-view :webview-styles="webviewStyles" :src="openUrl"></web-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#E02020'
				},
				title: '',
				openUrl: "",
				webviewStyles: {
					progress: {
						color: '#FF3333'
					}
				}
			}
		},
		onLoad() {
			this.openUrl = "https://www.baidu.com"
			
			const vm = this;
			// 接收信息的页面(子窗体向父窗体传递参数)
			uni.$on('to-parent', (data) => {
				uni.showToast({
					title: data.type + ', ' +  data.content
				})
				switch( data.type ){
					case '1':
					break;
					case '2':
					break;
					case '3':
					break;
					// .... 
				}
			});
		},
		methods: {
			onNavigationBarButtonTap(e) {

				const subNVue = uni.getSubNVueById('popup'); //  对应page.json的id

				// 向子窗体传递参数
				uni.$emit('from-parent',{
					type: '1',
					content: '父给子参数1'
				})

				// 1:子窗体从顶部进入（动画效果）, 2:显示原生子窗体的动画持续时间
				subNVue.show('slide-out-top', 250)
			},
		},
		beforeDestroy() {
			// 页面销毁之前 移除监听器
			uni.$off('to-parent')
		},
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
